package com.bing.mvc.validator;

import com.bing.entity.Post;
import com.bing.utils.AppContext;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Created by kaibb on 16-1-16.
 */
public class PostTitleUniqueValidator implements ConstraintValidator<PostTitleUnique,String>{
    @Override
    public void initialize(PostTitleUnique constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        Post post = AppContext.getBlogService().getPostByTitle(value);
        if(post==null){
            return true;
        }
        return false;
    }
}
